#include #include using namespace std; void displayFileHeader(ifstream& fin) { //1 2 bfType 19778 must always be set to 'BM' to declare that this is a .bmp-file. //3 4 bfSize ?? specifies the size of the file in bytes. //7 2 bfReserved1 0 must always be set to zero. //9 2 bfReserved2 0 must always be set to zero. //11 4 bfOffBits 1078 specifies the offset from the beginning of the file to the bitmap data char bfType[3]; unsigned int bfSize; unsigned short bfReserved1; unsigned short bfReserved2; unsigned int bfOffBits; fin.read(bfType, 2); // this should read BM bfType[2] = '\0'; fin.read((char*)&bfSize,4); //fin.read((char*)&bfReserved1,2); //fin.read((char*)&bfReserved2,2); //fin.seekg(10); //fin.seekg(10,ios::beg); //fin.seekg(10,ios::end); fin.seekg(4,ios::cur); fin.read((char*)&bfOffBits,4); cout << bfType << endl; cout << bfSize << endl; //cout << bfReserved1 << endl; //cout << bfReserved2 << endl; cout << bfOffBits << endl; } void displayInfoHeader(ifstream& fin) { //15 4 biSize 40 specifies the size of the BITMAPINFOHEADER structure, in bytes. //19 4 biWidth 100 specifies the width of the image, in pixels. //23 4 biHeight 100 specifies the height of the image, in pixels. //27 2 biPlanes 1 specifies the number of planes of the target device, must be set to zero. //29 2 biBitCount 8 specifies the number of bits per pixel. //31 4 biCompression 0 Specifies the type of compression, usually set to zero (no compression). //35 4 biSizeImage 0 specifies the size of the image data, in bytes. If there is no compression, it is valid to set this member to zero. //39 4 biXPelsPerMeter 0 specifies the the horizontal pixels per meter on the designated targer device, usually set to zero. //43 4 biYPelsPerMeter 0 specifies the the vertical pixels per meter on the designated targer device, usually set to zero. //47 4 biClrUsed 0 specifies the number of colors used in the bitmap, if set to zero the number of colors is calculated using the biBitCount member. //51 4 biClrImportant 0 specifies the number of color that are 'important' for the bitmap, if set to zero, all colors are important. unsigned int biSize; unsigned int biWidth; unsigned int biHeight; unsigned short biPlanes; unsigned short biBitCount; unsigned int biCompression; unsigned int biSizeImage; unsigned int biXPelsPerMeter; unsigned int biYPelsPerMeter; unsigned int biClrUsed; unsigned int biClrImportant; fin.read((char*)&biSize,4); fin.read((char*)&biWidth,4); fin.read((char*)&biHeight,4); fin.read((char*)&biPlanes,2); fin.read((char*)&biBitCount,2); fin.read((char*)&biCompression,4); fin.read((char*)&biSizeImage,4); fin.read((char*)&biXPelsPerMeter,4); fin.read((char*)&biYPelsPerMeter,4); fin.read((char*)&biClrUsed,4); fin.read((char*)&biClrImportant,4); cout << "biSize = " << biSize << endl; cout << "biWidth = " << biWidth << endl; cout << "biHeight = " << biHeight << endl; cout << "biPlanes = " << biPlanes << endl; cout << "biBitCount = " << biBitCount << endl; cout << "biCompression = " << biCompression << endl; cout << "biSizeImage = " << biSizeImage << endl; cout << "biXPelsPerMeter = " << biXPelsPerMeter << endl; cout << "biYPelsPerMeter = " << biYPelsPerMeter << endl; cout << "biClrUsed = " << biClrUsed << endl; cout << "biClrImportant = " << biClrImportant << endl; } void main() { ifstream fin("test.bmp",ios::binary); displayFileHeader(fin); displayInfoHeader(fin); fin.close(); }